package com.chezhujie.www.service;

import com.chezhujie.www.domain.Czjcity;
import com.chezhujie.www.persistence.CzjcityMapper;
import com.sys.core.exception.ClassCheckException;
import com.sys.core.page.Pagination;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.ui.ModelMap;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;


/**
 * 城市
 * Created by 汤伟杰 on 2017/5/23.
 */
@Service
public class CzjcityService {
    @Autowired
    private CzjcityMapper czjcityMapper;

    public Pagination list(int pageNo, int pageSize, Map<String, Object> params, ModelMap model) throws Exception {

        Pagination pagination = new Pagination();
        pagination.setPageNo(pageNo);
        pagination.setPageSize(pageSize);
        params.putAll(pagination.toMap());
        int count = czjcityMapper.getTotalRows(params);
        List<Map<String, Object>> list = czjcityMapper.getList(params);
        pagination.setTotalCount(count);
        pagination.setList(list);
        return pagination;
    }


    public void insert(Czjcity czjcity){
        czjcityMapper.insert(czjcity);
    }

    public void update(Czjcity czjcity){
        czjcityMapper.update(czjcity);
    }
    public void deleteById(String id){
        czjcityMapper.deleteById(id);
    }
    public void deleteByIds(List<String> list){
        czjcityMapper.deleteByIds(list);
    }
    public Czjcity queryById(String id){
        return czjcityMapper.queryById(id);
    }
    public List<Czjcity> queryByIds(List<String> list){
        List<Czjcity> listCzjcity = czjcityMapper.queryByIds(list);
        if(listCzjcity==null){
            listCzjcity = new ArrayList<Czjcity>();
        }
        return listCzjcity;
    }
    public List<Map<String,Object>> getListFatherID(Map<String, Object> param) {
        return czjcityMapper.listFatherID(param);
    }

    public void checkEntity(Czjcity czjcity) throws Exception {
            if(czjcity.getCity().length()<255){
                throw new ClassCheckException("城市城市不能超过255个字符");
            }


    }
}
